import { AxiosInstance} from 'axios';
import axios from 'axios'

const instance: AxiosInstance = axios.create({
  baseURL: 'http://localhost:8081/order',
  timeout: 2000,
  headers: {
    'Content-type': 'application/json'
  },

  withCredentials: true
})

async function findMatchOrder(userid: number) {
  let response = await instance.get('/', {
    params: {
      userid
    }
  })
  return response.data
}

async function insertOrder(order: Order) {
  let response = await instance.post('/', JSON.stringify(order))
  return response.data
}


async function deleteOrder(id: number) {
  let response = await instance.delete('/', {
    params: {
      id
    }
  })

  return response.data
}

async function updateOrder(order: Order) {
  let response = await instance.put('/', JSON.stringify(order))
  return response.data
}

export {
  insertOrder,
  findMatchOrder,
  deleteOrder,
  updateOrder
}